<template>
  <div class="modal-column">
    <div class="modal-column-full-body">
      <Form ref="form" :model="model" :rules="validationRules" :labelWidth="160" >
        <FormItem label="财务系统地址" prop="url" required>
          <Input   v-model="model.url"/>
        </FormItem>
        <FormItem label="财务系统账号" prop="mobile" required>
          <Input   v-model="model.mobile"/>
        </FormItem>
        <FormItem label="财务系统密码" prop="password" required>
          <Input   v-model="model.password" />
        </FormItem>
      </Form>
    </div>
    <div class="modal-column-right">
      <Button icon="fa fa-close" @click="$emit('close')" :loading="loading">
        取消
      </Button>
      <Button icon="fa fa-save"  color="primary" @click="confirm" :loading="loading">
        保存
      </Button>
    </div>
  </div>
</template>

<script>

import {message} from "heyui.ext";
import RelationAccount from "@js/api/RelationAccount";
import {CopyObj} from "@common/utils";

export default {
  name: "RelationAccountForm",
  emits: {
    close: null,
    success: null
  },
  props: {
    cwId: Number,
    id: Number,
  },
  data() {
    return {
      loading: false,
      accountSetsList: [],
      model: {
        id: null,
        mobile:'',
        url: '',
        password: '',
        relationCwId:null,
      },
      validationRules: {
      }
    }
  },
  methods: {
    confirm() {
      let validResult = this.$refs.form.valid();
      if (validResult.result) {
        this.loading = true;
        this.model.relationCwId = this.cwId
        RelationAccount.save(this.model).then(() => {
          message("保存成功~");
          this.$emit('success');
        }).finally(() => this.loading = false);
      }
    },
  },
  created() {
    console.log('id',this.id)
    if(this.id){
      RelationAccount.load(this.id).then(({data})=>{
        CopyObj(this.model, data);
      })
    }
  }
}
</script>
